package com.zhanqiao.controller;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/delete.do")
public class FansDeleteController extends HttpServlet{
    //客户端向这个服务器端发送删除请求

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf8");
        resp.setContentType("application/json;charset=utf-8");

        String uid = req.getParameter("uid");
        System.out.println(uid);

        //加载数据库
        DataSource dataSource = new ComboPooledDataSource();
        QueryRunner queryRunner = new QueryRunner(dataSource);
        String deletesql = "delete from user where uid ="+uid;
        try {
            int update = queryRunner.update(deletesql);
            System.out.println(update);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
